<template>

  <div class="base-container">
    <!-- <t-form ref="form" :data="queryParams" label-width="80"
      @submit="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }"
      @reset="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="平台名称" name="name">
            <t-input v-model="queryParams.name" clearable placeholder="请输入平台名称" style="width: 240px" />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="base" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form> -->
    <div class="btn-group-inline" style="display: flex;justify-content: space-between;">
      <t-button
        @click="dialog.objId = null; dialog.platformId = queryParams.platformId; dialog.header = '新增指标录入'; dialog.open_apply = true"
        variant="outline" theme="primary"
        v-if="$store.state.user.roles.includes('dwsby') || $store.state.user.roles.includes('admin')">
        <t-icon name="add" slot="icon" />
        新增指标
      </t-button>

      <t-button @click="reloadData" variant="outline" theme="primary">
        <t-icon name="refresh" slot="icon" />
        刷新
      </t-button>
    </div>
    <t-table rowKey="index" size="small" :data="dataList" :columns="columns" hover :pagination="pagination"
      :loading="dataLoading" :hideSortTips="true">
      <template #id="{ rowIndex }">
        {{ rowIndex + 1 }}
      </template>
      <template #status="{ row }">
        <t-tag @click="dialog.header = row.name; dialog.objId = row.id; dialog.open_approve_list = true;"
          class="cursor-pointer" :theme="handleTheme(row.status, dict.type.approve_status)" variant="light">
          {{ row.status | filterByDict(dict.type.approve_status) }}
        </t-tag>
      </template>

      <template #op="{ row }">
        <t-button size="small"
          @click="dialog.objId = row.id; dialog.header = row.name; dialog.open_project_detail = true" variant="text"
          class="t-button-link">
          <t-icon name="info-circle" slot="icon" />
          详情
        </t-button>
        <t-button
          @click="dialog.objId = row.id; dialog.platformId = queryParams.platformId; dialog.header = '修改指标'; dialog.open_apply = true"
          size="small" variant="text" class="t-button-link"
          v-if="$store.state.user.roles.includes('admin') || ($store.state.user.roles.includes('dwsby') && (row.status == 1 || row.status == 4))">
          <t-icon name="edit-1" slot="icon" />
          修改
        </t-button>
        <t-button theme="danger" @click="deletePlatform(row)" size="small" variant="text" class="t-button-link"
          v-if="$store.state.user.roles.includes('admin') || ($store.state.user.roles.includes('dwsby') && (row.status == 1 || row.status == 4))">
          <t-icon name="delete" slot="icon" />
          删除
        </t-button>
      </template>
    </t-table>
    <platform-score-detail-dialog :header="dialog.header" :objId="dialog.objId"
      :visible.sync="dialog.open_project_detail" v-if="dialog.open_project_detail"></platform-score-detail-dialog>
    <platform-score-apply @reload="reloadData" :header="dialog.header" :objId="dialog.objId"
      :platformId="dialog.platformId" :visible.sync="dialog.open_apply" v-if="dialog.open_apply"></platform-score-apply>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
      v-if="dialog.open_approve_list"></approve-list>

  </div>

</template>

<script>
import PlatformScoreDetailDialog from "./components/platform-score-detail-dialog.vue";
import PlatformScoreApply from "./platform-score-apply.vue";
import ApproveList from './components/approve-list.vue';
export default {
  dicts: ['approve_status'],
  components: {
    PlatformScoreDetailDialog,
    PlatformScoreApply,
    ApproveList
  },
  data () {
    return {
      dataLoading: false,
      visible: true,
      dataList: [],
      dialog: {
        open_project_detail: false,
        open_approve_list: false,
        open_apply: false,
        header: "",
        objId: 0,
        platformId: null,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        platformId: "",
      },
      columns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 100
        },
        {
          colKey: "firstName",
          title: "一级指标",
          align: "center",
          width: 200
        },
        {
          colKey: "secondName",
          title: "二级指标",
          align: "center",
          width: 200
        },
        {
          colKey: "thirdName",
          title: "考核内容",
          align: "center",
          width: 200
        },
        {
          colKey: "systemScore",
          title: "分值",
          align: "center",
        },
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
        },
        {
          colKey: "year",
          title: "取得年度",
          align: "center",
        },
        {
          colKey: "score",
          title: "本年度得分",
          align: "center",
        },
        {
          colKey: "status",
          title: "审批状态",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 220,
          fixed: 'right'
        },
      ],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  watch: {

  },
  async created () {

    const taskId = this.$route.params && this.$route.params.taskId;

    if (!taskId) {
      this.$message.error("任务id丢失返回项目");
      this.$router.push("/kjpt/platform/platform-index");
    }
    this.queryParams.platformId = taskId;
    this.getList()
  },
  methods: {
    reloadData () {
      this.pagination.current = 1;
      this.queryParams.pageNum = 1;
      this.getList()
    },
    deletePlatform (row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除平台名称为"${row.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.kjpt.project.deleteScore(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        }
      });
    },
    getList () {
      this.dataLoading = true;
      this.queryParams.pageNum = this.pagination.current || 1;
      this.$api.kjpt.project.scoreList(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.dataList = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped></style>
